package org.crumbleworks.crumbchat.server.controller;

import org.crumbleworks.crumbchat.common.data.Message;
import org.crumbleworks.crumbchat.server.console.ConsoleReader;

public class ConsoleController implements ServerControllerInterface {
    private ConsoleReader consoleReader;

    private ServerControllerInterface controller;

    public ConsoleController(ServerControllerInterface controller) {
        this.controller = controller;

        consoleReader = new ConsoleReader(this);
    }

    @Override
    public void bindPorts(int tcpPort, int udpPort) {
        controller.bindPorts(tcpPort, udpPort);
    }

    @Override
    public void unbindPorts(boolean shutdownAfterUnbind) {
        controller.unbindPorts(shutdownAfterUnbind);
    }

    @Override
    public void sendMessageToClients(String text) {
        controller.sendMessageToClients(text);
    }

    @Override
    public void putMessageToChat(Message message) {
        System.out.println(message.getUsername() + ": " + message.getMessage() + "\n");
    }

    @Override
    public void showBindError(int tcpPort, int udpPort) {
        System.err.println("Konnte Ports nicht auf 'TCP: " + tcpPort + "' und/oder 'UDP: " + udpPort + "' binden.");
    }

    @Override
    public void shutdown() {
        consoleReader.stop();
    }

    @Override
    public void parseInput(String input) {
        controller.parseInput(input);
    }
}
